package com.SoilMM.controller;

import com.SoilMM.entity.MtimeMonitEntity;
import com.SoilMM.service.MtimeMonitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author ：GuoCS
 * @date ：Created 2021/6/29 18:41
 * @description：曲线分析
 */
@RestController
@RequestMapping("/analysisMonit")
public class AnalysisController {
    @Autowired
    MtimeMonitService mtimeMonitService;
    @RequestMapping("analysis")
    public Map<String,Object> Analysis(String date1 , String date2){
        int dateStart = Integer.parseInt(date1.substring(8,10));
        int dateEnd = Integer.parseInt(date2.substring(8,10));
        if (dateStart>dateEnd){
            int tmp = dateStart;
            dateStart = dateEnd;
            dateEnd = tmp;
        }
        List<Integer> ids = new ArrayList<>();
        List<String> date = new ArrayList<>();
        for (int i=dateStart;i <= dateEnd; i++){
            ids.add(i);
        }
        Collection<MtimeMonitEntity> mtimeMonitEntities = mtimeMonitService.listByIds(ids);
        Map<String,Object> map = new HashMap<>();
        if (mtimeMonitEntities != null) {
            map.put("code",6666);
            map.put("date",ids);
            map.put("message","折线图绘画完成");
            map.put("entities",mtimeMonitEntities);
        }else map.put("message","查询失败");
        return map;
    }
}
